#include "ferrylog.h"
#include <QJsonArray>
#include <QJsonObject>
#include <QDebug>

FerryLog *ferryLog;
FerryLog::FerryLog() {
    ferryLog = this;
}

void FerryLog::init()
{
#ifndef QT_NO_DEBUG
    qDebug() << Q_FUNC_INFO << __LINE__ ;
#endif
    ferryLog = this;
    addDataBase(getDbName(), getConnectName());

//     setTableName("QRTZ_BLOB_TRIGGERS");
//     if(!checkTableExists(getTableName())) {
//         createTable(getTableName(), \
//                     "sched_name TEXT(255), trigger_name TEXT(255), trigger_group TEXT(255), blob_data TEXT(255)");
//     }

//     setTableName("QRTZ_CALENDARS");
//     if(!checkTableExists(getTableName())) {
//         createTable(getTableName(), \
//                     "sched_name TEXT(255), calendar_name TEXT(255), calendar TEXT(255)");
//     }

//     setTableName("QRTZ_FIRED_TRIGGERS");
//     if(!checkTableExists(getTableName())) {
//         createTable(getTableName(), \
//                     "sched_name TEXT(255), entry_id TEXT(255), trigger_name TEXT(255), trigger_group TEXT(255), instance_name TEXT(255), fired_time TEXT(255), sched_time TEXT(255), priority TEXT(255), state TEXT(255), job_name TEXT(255), job_group TEXT(255), is_nonconcurrent TEXT(255),requests_recovery TEXT(255)");
//     }

//     setTableName("QRTZ_JOB_DETAILS");
//     if(!checkTableExists(getTableName())) {
//         createTable(getTableName(), \
//                     "sched_name TEXT(255), job_name TEXT(255), job_group TEXT(255), description TEXT(255), job_class_name TEXT(255), is_durable TEXT(255), is_nonconcurrent TEXT(255), is_update_data TEXT(255), requests_recovery TEXT(255), job_data TEXT(255)");
//     }

//    setTableName("eu_area");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "area_id TEXT(255), area_name TEXT(255), parent_id TEXT(255)");
//    }

//    setTableName("eu_area_user");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), area_id TEXT(255), user_id TEXT(255), user_name TEXT(255), area_name TEXT(255)");
//    }

//    setTableName("eu_safe");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), computer_ip TEXT(255), mac_ip TEXT(255), id_safe TEXT(255)");
//    }
//    setTableName("eu_usbs");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), number TEXT(255), usb_permissions TEXT(255), apply_time TEXT(255), department_id TEXT(255), user_name TEXT(255), user_id TEXT(255), status TEXT(255), area_id TEXT(255), department_name TEXT(255), area_name TEXT(255), create_by TEXT(255), create_time TEXT(255), update_by TEXT(255), update_time TEXT(255), remark TEXT(255), is_enable TEXT(255)");
//    }

//    setTableName("file_download");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), file_name TEXT(255), file_path TEXT(255), user_id TEXT(255), user_name TEXT(255), download_time TEXT(255), uninstall_code TEXT(255)");
//    }

//    setTableName("file_upload");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), file_name TEXT(255), file_path TEXT(255), user_id TEXT(255), user_name TEXT(255), upload_time TEXT(255)");
//    }

//    setTableName("gen_table");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "table_id TEXT(255), table_name TEXT(255), table_comment TEXT(255), sub_table_name TEXT(255), sub_table_fk_name TEXT(255), class_name TEXT(255), tpl_category TEXT(255), package_name TEXT(255), module_name TEXT(255), business_name TEXT(255), function_name TEXT(255), function_author TEXT(255), gen_type TEXT(255), gen_path TEXT(255), options TEXT(255), create_by TEXT(255), create_time TEXT(255), update_by TEXT(255), update_time TEXT(255), remark TEXT(255)");
//    }

//    setTableName("gen_table_column");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "column_id TEXT(255), table_id TEXT(255), column_name TEXT(255), column_comment TEXT(255), column_type TEXT(255), java_type TEXT(255), java_field TEXT(255), is_pk TEXT(255), is_increment TEXT(255), is_required TEXT(255), is_insert TEXT(255), is_edit TEXT(255), is_list TEXT(255), is_query TEXT(255), query_type TEXT(255), html_type TEXT(255), dict_type TEXT(255), sort TEXT(255), create_by TEXT(255), create_time TEXT(255), update_by TEXT(255), update_time TEXT(255)");
//    }

//    setTableName("operate_log");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), file_name TEXT(255), operate_type TEXT(255), operate_time TEXT(255), usb_id TEXT(255), user_id TEXT(255)");
//    }

//    setTableName("role_audit");
//    if(!checkTableExists(getTableName())) {
//        createTable(getTableName(), \
//                    "id TEXT(255), user_id TEXT(255), role_id TEXT(255), audit_role_id TEXT(255), temp_role_time_begin TEXT(255), temp_role_time_end TEXT(255), status TEXT(255), create_time TEXT(255), update_time TEXT(255)");
//    }


    setTableName("eu_usb_info");
    if(!checkTableExists(getTableName())) {
        createFerryTable(getTableName(), \
                    "ID BLOB(255), usb_number BLOB(255), readCount BLOB(255), writeCount BLOB(255), lastReadTime BLOB(255), lastWriteTime BLOB(255), area_id BLOB(255), user_id BLOB(255), insertionTime BLOB(255), removalTime BLOB(255), computerIp BLOB(255), installedSP BLOB(255), dept_id BLOB(255), macIp BLOB(255), nick_name BLOB(255), department_name BLOB(255), area_name BLOB(255), role_id BLOB(255), create_by BLOB(255), create_time BLOB(255), update_by BLOB(255), update_time BLOB(255), remark BLOB(255)" );
    }

    setTableName("usb_id");
    if(!checkTableExists(getTableName())) {
        createTable(getTableName(), \
                    "usb_id BLOB" );
    }

    setTableName("usb_password");
    if(!checkTableExists(getTableName())) {
        createTable(getTableName(), \
                    "usb_password BLOB" );
    }

    setTableName("key");
    if(!checkTableExists(getTableName())) {
        createTable(getTableName(), \
                    "key BLOB" );
    }
}

void FerryLog::isSqliteCipherLoaded()
{
#ifndef QT_NO_DEBUG
    qDebug() << Q_FUNC_INFO << __LINE__;
    qDebug() << QSqlDatabase::drivers();
#endif
}
